<?

if ($DATA['component']['id'] && ($g = (int)param('gallery'))) {

	// image editor

	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_id_gallery	= D_GALLERY_DATA;

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('text', 'value');	// which fields are stored in language variations


	$s = array_extend( array('path' => 'album', 'tn' => FP_TN_DIR, 'w' => 800, 'h' => 600, 'tnw' => 96, 'tnh' => 96, 'gw' => 96, 'gh' => 96, 'caption' => '', 'gparam' => 'gallery', 'param' => 'id'), $DATA['component']['settings']);

	$s['path'] = createdir(FP_UPLOAD_PATH."$s[path]/$g/");
	createdir($s['path'].$s['tn']);

	if ($a = addslashes(param($_param))) {

		switch (action(array('editor_save'))) {
		
			case 'editor_save':
				$dat = array('id_data' => $_id_gallery, 'assoc' => $s['path'], 'name' => $a);
				foreach ($_values as $v) $dat[$v] = postdata($v);
	
				dataset('db_delete', tb('data'), "id_data=$_id_gallery AND assoc=\"".h($s['path'])."\" AND name=\"".h($a)."\"");
				dataset('db_insert', tb('data'), $dat );
	
				takeImage('image', $s['w'], $s['h'], $s['path'].$a, $s['tnw'], $s['tnh'], $s['path'].$s['tn'].$a );

				return _transformURL($CURRENT->url, array('remove_param' => $_param));	// end of component edition
				break;
		}
		
		$DATA['object'] = array('value' => '', 'text' => '', 'image' => checkImage($s['path'], $a));

		if ($descr = datafetch('db_item', tb('data'), "id_data=$_id_gallery AND assoc=\"{$s['path']}\" AND name=\"$a\"")) {
			$DATA['object']['value'] = $descr['value'];
			$DATA['object']['text'] = $descr['text'];
		}
	}

	return false;
	
} else exit;

?>